package com.careerraiser.testing;

import java.util.Arrays;
import java.util.TreeSet;
import java.util.Iterator;

import com.careerraiser.child.ComparableDog;
import com.careerraiser.child.Dog;

public class TreeExample {

	public static void main(String[] args) {
		TreeSet<Dog> dogList2=new TreeSet<Dog>();
		Dog dog1 =new ComparableDog("1Dog",1);
		Dog dog2 =new ComparableDog("ADog",2);
		Dog dog4 =new ComparableDog("4Dog",4);
		Dog dog3 =new ComparableDog("removeme",5);
		
		Dog dog41 =new ComparableDog("4Dog1",4);
		
		System.out.println("List add output : "+dogList2.add(dog4));
		System.out.println(dogList2.add(dog2));
		System.out.println(dogList2.add(dog1));
		System.out.println(dogList2.add(dog3));
		//below value will not b added to treeset.
	    //since the value 4 is already there.
		System.out.println(dogList2.add(dog41));
		
		for (Dog dog : dogList2) {
			System.out.println(dog.getName());
		}

		//example of using iterator
		//this is first way
	Iterator i=dogList2.iterator();
	while(i.hasNext()){
		Dog dogitr=(Dog) i.next();
		if(dogitr.getName().equals("removeme")){
			i.remove();
		}
	}
	//this is another way where iterator is used in background.
	for (Dog dog : dogList2) {
		System.out.println(dog.getName());
	}
}

}
